package com.moody.hibernate.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.moody.hibernate.domain.CustLimit;

/**
 * A data access object (DAO) providing persistence and search support for
 * CustLimit entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.moody.hibernate.domain.CustLimit
 * @author MyEclipse Persistence Tools
 */

public class CustLimitDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(CustLimitDAO.class);
	// property constants
	public static final String CUST_ID = "custId";
	public static final String CUST_NAME = "custName";
	public static final String PDFACTOR = "pdfactor";
	public static final String SOLVENT_FACTOR = "solventFactor";
	public static final String INDUSTRY_FACTOR = "industryFactor";
	public static final String REGION_FACTOR = "regionFactor";
	public static final String NET_ASSET = "netAsset";
	public static final String OBBALANCE = "obbalance";
	public static final String INIT_LIMIT = "initLimit";
	public static final String PDLIMIT = "pdlimit";
	public static final String RLIMIT = "rlimit";
	public static final String FINAL_LIMIT = "finalLimit";
	public static final String REMARK = "remark";
	public static final String UPDATE_USER_ID = "updateUserId";
	public static final String UPDATE_ORG_ID = "updateOrgId";
	public static final String UPDATE_DATE = "updateDate";

	protected void initDao() {
		// do nothing
	}

	public void save(CustLimit transientInstance) {
		log.debug("saving CustLimit instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(CustLimit persistentInstance) {
		log.debug("deleting CustLimit instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public CustLimit findById(java.lang.String id) {
		log.debug("getting CustLimit instance with id: " + id);
		try {
			CustLimit instance = (CustLimit) getHibernateTemplate().get(
					"com.moody.hibernate.CustLimit", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(CustLimit instance) {
		log.debug("finding CustLimit instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding CustLimit instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from CustLimit as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCustId(Object custId) {
		return findByProperty(CUST_ID, custId);
	}

	public List findByCustName(Object custName) {
		return findByProperty(CUST_NAME, custName);
	}

	public List findByPdfactor(Object pdfactor) {
		return findByProperty(PDFACTOR, pdfactor);
	}

	public List findBySolventFactor(Object solventFactor) {
		return findByProperty(SOLVENT_FACTOR, solventFactor);
	}

	public List findByIndustryFactor(Object industryFactor) {
		return findByProperty(INDUSTRY_FACTOR, industryFactor);
	}

	public List findByRegionFactor(Object regionFactor) {
		return findByProperty(REGION_FACTOR, regionFactor);
	}

	public List findByNetAsset(Object netAsset) {
		return findByProperty(NET_ASSET, netAsset);
	}

	public List findByObbalance(Object obbalance) {
		return findByProperty(OBBALANCE, obbalance);
	}

	public List findByInitLimit(Object initLimit) {
		return findByProperty(INIT_LIMIT, initLimit);
	}

	public List findByPdlimit(Object pdlimit) {
		return findByProperty(PDLIMIT, pdlimit);
	}

	public List findByRlimit(Object rlimit) {
		return findByProperty(RLIMIT, rlimit);
	}

	public List findByFinalLimit(Object finalLimit) {
		return findByProperty(FINAL_LIMIT, finalLimit);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByUpdateUserId(Object updateUserId) {
		return findByProperty(UPDATE_USER_ID, updateUserId);
	}

	public List findByUpdateOrgId(Object updateOrgId) {
		return findByProperty(UPDATE_ORG_ID, updateOrgId);
	}

	public List findByUpdateDate(Object updateDate) {
		return findByProperty(UPDATE_DATE, updateDate);
	}

	public List findAll() {
		log.debug("finding all CustLimit instances");
		try {
			String queryString = "from CustLimit";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public CustLimit merge(CustLimit detachedInstance) {
		log.debug("merging CustLimit instance");
		try {
			CustLimit result = (CustLimit) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(CustLimit instance) {
		log.debug("attaching dirty CustLimit instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(CustLimit instance) {
		log.debug("attaching clean CustLimit instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CustLimitDAO getFromApplicationContext(ApplicationContext ctx) {
		return (CustLimitDAO) ctx.getBean("CustLimitDAO");
	}

	public void update(CustLimit custLimit) {
		log.debug("saving CustInfo instance");
		try {
			getHibernateTemplate().update(custLimit);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
}